package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.model.order.OrderInfo;
import com.atguigu.gmall.order.client.OrderFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class PaymentController {
    @Autowired
    private OrderFeignClient orderFeignClient;

    /**
     * 支付页
     * @param request
     * @return
     */
    @GetMapping("pay.html")
    public String paySuccess(HttpServletRequest request){

//        获取订单订单id
        String orderId = request.getParameter("orderId");
//        获取订单信息
        OrderInfo orderInfo = orderFeignClient.getOrderInfo(Long.valueOf(orderId));

        request.setAttribute("orderInfo",orderInfo);

        return "payment/pay";
    }


    /**
     * 返回支付成功页
     * @return
     * http://api.gmall.com/api/payment/alipay/callback/return?charset=utf-8&out_trade_no=ATGUIGU165323037670130&method=alipay.trade.page.pay.return&total_amount=0.01&sign=PI8ysvbJktYg7MphNrE3eGN4FnBarD4wz7ZRKI%2BjVye0HVOAwkafLb2wAcucjD3ihxfN5MpoB18Kf49kc%2BmfwAp9L8itUH%2FA5zm96weltKIZROSplu%2FTPKQM0M12JaqPhZZ2YkPschAMvsgYtM28uOThAQrIyJopP06NJXN7MIkluwdbJ6xoQK2TaQ6qXKA5Cx9DyOh970j%2BBUqcGMIglXDvF2BCKyj3sFG%2B7ScUItrqdbFjDMZvlB28WSwE%2BqjNTh56HeOqCFnZ8WKJgcaP5lzdE9NQLaDWWxGeYUHzreZQqDuAg0MdHyCnpnkGLUjx%2FdguabxdqXenYRMJL8iP8g%3D%3D&trade_no=2022052222001452511413616520&auth_app_id=2021001163617452&version=1.0&app_id=2021001163617452&sign_type=RSA2&seller_id=2088831489324244&timestamp=2022-05-22+22%3A40%3A31
     */
    @GetMapping("pay/success.html")
    public String success() {
        return "payment/success";
    }
}
